import router from "@src/router";
import {
  OPEN_STATE_TEXT,
  PROJECT_STATE,
  PROJECT_TYPE,
  RESOURCES_STATE,
} from "@src/sp-reservation/constant/index.js";
import { resolveTimeAddZero } from "@src/common/reservation/config/index.js";
import base from "@src/store/base";
import { storeBindingsBehavior } from "mobx-miniprogram-bindings";

Component({
  behaviors: [storeBindingsBehavior, router.routerBehavior],
  storeBindings: [
    {
      store: base,
      fields: ["isiPhoneX", "themeColor", "themeTitleColor"],
    },
  ],
  options: {
    addGlobalClass: true,
    isHiddenTips: true,
  },
  properties: {
    imageList: {
      type: Array,
      value: [],
    },
    shopInfo: {
      type: Object,
      value: {},
    },
    isScrollToTop: {
      type: Boolean,
      value: false,
    },
    tabsActived: {
      type: Number,
      value: PROJECT_TYPE,
    },
  },

  data: {
    OPEN_STATE_TEXT,
    indicatorIndex: 1,
    // tabsActived: PROJECT_TYPE,
    tabsOptions: [PROJECT_STATE, RESOURCES_STATE],
    height: 44,
  },
  ready() {
    this.initNav();
  },
  methods: {
    resolveTimeAddZero,
    initNav() {
      const systemInfo = wx.getSystemInfoSync();
      let navBarHeight = 0;
      if (/ios/i.test(systemInfo.platform)) {
        navBarHeight = 44;
      } else if (systemInfo.platform === "devtools") {
        navBarHeight = 44;
      } else {
        navBarHeight = 48;
      }
      this.setData({
        statusBarHeight: systemInfo.statusBarHeight,
        navBarHeight: navBarHeight,
        height: navBarHeight + systemInfo.statusBarHeight,
      });
    },
    handleToShopDetail(e) {
      // const {
      //   currentTarget: {
      //     dataset: {
      //       value: { value },
      //     },
      //   },
      // } = e;
      router.push({
        name: "reservation/detail",
        params: {
          shopId: this.data.shopInfo.shopId,
          // navIndex: e.currentTarget.dataset.index,
        },
      });
    },
    handleToShopList() {
      // router.push({
      //   name: "reservation/shopList",
      //   events: {
      //     changeShop: (shopId) => {
      //       if (shopId !== this.data.shopId) {
      //         this.triggerEvent("changeShop", { shopId: shopId });
      //       }
      //     },
      //   },
      // });
      router.push({
        name: 'mall/store-list',
        params: { shopId: this.data.shopId, storeType: 'reservation' }
      })
    },
    onClickChangeActivedTab(e) {
      const {
        currentTarget: {
          dataset: {
            value: { value },
          },
        },
      } = e;
      this.triggerEvent("ChangeActivedTab", { value });
    },
  },
});
